import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * openApp - 三方应用管理
 * @date: 2018-10-10

 */
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function openAppApi() {
  return isTenantRoleLevel() ? "/cpaas/v1/".concat(tenantId, "/open-app") : "/cpaas/v1/open-app";
}
/**
 * 查询列表数据
 * @async
 * @function fetchOpenApp
 * @param {Object} params - 查询参数
 * @param {String} [params.page = 0] - 页码
 * @param {String} [params.size = 0] - 页数
 */


export function fetchOpenAppList(_x) {
  return _fetchOpenAppList.apply(this, arguments);
}
/**
 * 查询详细数据
 * @async
 * @function fetchOpenAppDetail
 * @param {Object} params - 查询参数
 * @param {string} params.openAppId - 三方应用ID
 */

function _fetchOpenAppList() {
  _fetchOpenAppList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi()), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchOpenAppList.apply(this, arguments);
}

export function fetchOpenAppDetail(_x2) {
  return _fetchOpenAppDetail.apply(this, arguments);
}
/**
 * 创建
 * @async
 * @function createOpenApp
 * @param {object} params - 创建参数对象
 * @param {string} params.appCode - 应用编码
 * @param {string} params.appId - appId
 * @param {string} params.orderSeq - 序号
 * @param {string} params.appImage - 应用图片
 * @param {string} params.appName - 应用名称
 * @param {string} params.appKey - 授权码
 * @param {string} params.redirectUri - 回调地址
 * @param {string} params.authorizePath - 认证码地址
 * @param {string} params.tokenPath - AccessToken地址
 * @param {string} params.refreshTokenPath - RefreshToken地址
 * @param {string} params.selfPath - 个人信息地址
 * @param {string} params.scope - 授权列表
 */

function _fetchOpenAppDetail() {
  _fetchOpenAppDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi(), "/").concat(params.openAppId), {
              method: 'GET',
              query: params.openAppId
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchOpenAppDetail.apply(this, arguments);
}

export function createOpenApp(_x3) {
  return _createOpenApp.apply(this, arguments);
}
/**
 * 更新
 * @async
 * @function updateOpenApp
 * @param {Object} params - 查询参数
 * @param {string} params.appCode - 应用编码
 * @param {string} params.appId - appId
 * @param {string} params.orderSeq - 序号
 * @param {string} params.appImage - 应用图片
 * @param {string} params.appName - 应用名称
 * @param {string} params.appKey - 授权码
 * @param {string} params.redirectUri - 回调地址
 * @param {string} params.authorizePath - 认证码地址
 * @param {string} params.tokenPath - AccessToken地址
 * @param {string} params.refreshTokenPath - RefreshToken地址
 * @param {string} params.selfPath - 个人信息地址
 * @param {string} params.scope - 授权列表
 */

function _createOpenApp() {
  _createOpenApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createOpenApp.apply(this, arguments);
}

export function updateOpenApp(_x4) {
  return _updateOpenApp.apply(this, arguments);
}
/**
 * 启用
 * @async
 * @function enabledOpenApp
 * @param {Object} params - 查询参数
 * @param {string} params.openAppId - 三方应用ID
 */

function _updateOpenApp() {
  _updateOpenApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateOpenApp.apply(this, arguments);
}

export function enabledOpenApp(_x5) {
  return _enabledOpenApp.apply(this, arguments);
}
/**
 * 禁用
 * @async
 * @function disabledOpenApp
 * @param {Object} params - 查询参数
 * @param {string} params.openAppId - 三方应用ID
 */

function _enabledOpenApp() {
  _enabledOpenApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi(), "/enabled"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _enabledOpenApp.apply(this, arguments);
}

export function disabledOpenApp(_x6) {
  return _disabledOpenApp.apply(this, arguments);
}
/**
 * 删除
 * @async
 * @function deleteOpenApp
 * @param {String} params.enabledFlag - 是否启用
 * @param {string} params.openAppId - 三方应用ID
 */

function _disabledOpenApp() {
  _disabledOpenApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi(), "/disabled"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _disabledOpenApp.apply(this, arguments);
}

export function deleteOpenApp(_x7) {
  return _deleteOpenApp.apply(this, arguments);
}

function _deleteOpenApp() {
  _deleteOpenApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_IAM).concat(openAppApi()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _deleteOpenApp.apply(this, arguments);
}